/*
* Copyright © 2024 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#ifndef LIBS_TIME_H
#define LIBS_TIME_H

#include <time.h>
#include <stdio.h>
#include <sys/time.h>
#include "./malloc.h"

#define MAX_TIMEZONES 500

struct Ttm {
    int tm_sec;
    int tm_min;
    int tm_hour;
    int tm_mday;
    int tm_mon;
    int tm_year;
    int tm_wday;
    int tm_yday;
    int tm_isdst;
};

struct Tz {
    const char *name;
    int         utc_offset;
    int         dst_offset;
    int         dst_start_month;
    int         dst_end_month;
};

typedef long time_t;
extern struct Tz timezones[MAX_TIMEZONES];
extern int timezone_count;

char        *Sasctime(const struct Ttm *timeptr);
clock_t      Sclock(void);
char        *Sctime(const time_t *timer);
double       Sdifftime(time_t time1, time_t time2);
struct Ttm  *Sgmtime(const time_t *timer);
struct Ttm  *Slocaltime(const time_t *timer);
time_t       Smktime(struct Ttm *timeptr);
size_t       Sstrftime(char *str, size_t maxsize, const char *format, const struct Ttm *timeptr);
time_t       Stime(time_t *timer);
int          Stimespec_get(struct timespec *ts, int base);
int          Sis_dst(struct Tz *tz, struct Ttm *tm);
struct Ttm  *Sconvert_to_localtime(const time_t *timer, struct Tz *tz);

#endif //LIBS_TIME_H